import { postJson, deleteJson, putJson, get } from "@/common/VueAxios"
import type { ApiResult, ApiPageResult, PageInfo, SelectRows } from "./basemodel"

export interface Server {
    id?: number
    createtime?: string
    ip?: string
    password?: string
    port?: number
    username?: string
}

export interface ServerSearch extends PageInfo {
    ip?: string
}

export function save(dto: Server) {
    return dto.id == undefined || dto.id == 0 ? create(dto) : update(dto)
}

export function create(dto: Server) {
    return postJson<Server, ApiResult>("/server", dto)
}

export function update(dto: Server) {
    return putJson<Server, ApiResult>("/server", dto)
}

export function removeById(id: number) {
    return remove([id])
}

export function remove(ids?: number[]) {
    return deleteJson<number[] | undefined, ApiResult>("/server", ids)
}

export function getpage(dto: ServerSearch) {
    return get<PageInfo, ApiPageResult<Server>>("/server/getpage", dto)
}
export function getSelectRows() {
    return get<any, ApiResult<SelectRows[]>>("/server/getselectrows", {})
}
